var $;
var from;
var ids = 0;
layui.use(['form', 'laydate', 'layer'], function () {
  $ = layui.$;
  from = layui.form;
  var layer = layui.layer;
  var laydate = layui.laydate;
  laydate.render({
    elem: '#begyear',
  })
  laydate.render({
    elem: '#begtime',
    type: 'time'
  })
  laydate.render({
    elem: "#endyear",
  })
  laydate.render({
    elem: "#endtime",
    type: 'time'
  })
  $("#begin").blur(function () {
    var beg = $("#beg").val();
    var begin = $("#begin").val();
    if (begin < beg) {
      layer.tips('超出历史回放的范围', "#begin")
    }
  })
  $("#end").blur(function () {
    var ends = $("#ends").val();
    var end = $("#end").val();
    console.log(end)
    if (end < ends) {
      layer.tips('超出历史回放的范围', "#end")
    }
  })


})


function child(num2) {
  let year = num2.substr(0, 8)
  let time = num2.substr(8);
  let year1 = JSON.parse(year.substr(0, 4));//年
  let month1 = parseInt(year.substr(4, 2));//月
  let day1 = parseInt(year.substr(6, 2));//日
  var theTime = parseInt(time);// 秒
  if (theTime > 60) {
    middle = Math.floor(theTime / 60);
    theTime = (theTime % 60);
    if (middle > 60) {
      hour = Math.floor(middle / 60);
      middle = (middle % 60);
      if (hour > 24) {
        day = Math.floor(hour / 24);
        hour = (hour % 60);
        hour = hour - (day * 24)
      }
    }
  }
  var result = "" + (theTime);
  if (middle > 0) {
    result = "" + (middle) + ":" + result;
  }
  if (hour > 0) {
    result = "" + (hour) + ":" + result;
  }
  var offset = new Date().getTimezoneOffset() * 60 * 1000;
  var gmtdate = new Date(year1, month1, day1, hour, middle, theTime).getTime();
  var date = new Date(gmtdate - offset);
  var months;
  if (date.getMonth() == 0) {
    months = 12
  } else {
    months = date.getMonth();
  }

  var st = date.getFullYear() + "-" + months + "-" + date.getDate() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
  $("#ends").val(st);
}
var retdata = function () {
  let begyear = $("#begyear").val();
  let begtime = $("#begtime").val();
  let endyear = $("#endyear").val();
  let endtime = $("#endtime").val();
  if (begyear == "" || begtime == "" || endyear == "" || endtime == "") {
    return false;
  } else {
    begyear = begyear.replace("-", "/");
    endyear = endyear.replace("-", "/");
    begyear = begyear.replace("-", "/");
    endyear = endyear.replace("-", "/");
    let begmin = new Date(begyear + " " + begtime);
    let begmax = new Date(endyear + " " + endtime);
    if (begmin > begmax) {
      return false;
    }
    var date = { begin: begyear + " " + begtime, end: endyear + " " + endtime };
    return date;
  }
}